package com.campus.web.controller;

import com.campus.app.mapper.SocietyForMapper;
import com.campus.app.mapper.TeacherMapper;

import com.campus.app.service.*;
import com.campus.commons.entity.*;


import com.campus.commons.entity.Class;

import com.campus.commons.utils.Error;
import com.campus.commons.utils.Result;
import com.campus.commons.utils.Tool;
import com.campus.config.lifecycle.CustomInit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import java.util.ArrayList;
import java.util.List;


@Controller
public class IndexController {
    @Autowired
    //初始化类
    private CustomInit customInit;
    @Autowired
    private UsersService usersService;
    @Autowired
    private RolesService rolesService;
    // web目录; 协议 ip + 端口+项目名;
    public static String webPath;
    //文件资源目录
    public static String filePath = "/www/WebFile/";

    @PostMapping("/init")
    @ResponseBody
    public Result init() {
        try {
            customInit.init();
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(Error.Other_E1R, "发生异常，初始化失败");
        }
    }

    @GetMapping({"/test"})
    public String toTest() {
        return "test";
    }

    @GetMapping({"/"})
    public String toIndex(HttpSession session) {
        // 用户信息Info  等登录放开，把这个user放开；
//        User user= (User) session.getAttribute("user");

        //<editor-fold desc="Login页面开放就删了">
        // 还有把/menu/int/ 查询的菜单该了; 要不然老师目前还没读取菜单的权限;
        User user = new User();
//        user.setId(4);
        user.setDeid(1);
        user.setRoleid(2);

        session.setAttribute("user", user);
        session.setAttribute("identification", new OnlyIdentification(1, IdentificationType.RoleType_1, "张三"));
        //</editor-fold>
//        session.setAttribute("identification",usersService.getIdentificationForUserId(user.getId()));
        session.setAttribute("role", rolesService.getRoleById(user.getRoleid()));
        return "home/index";
    }

    @GetMapping({"/index"})
    public String toIndex_content() {
        return "home/index-content";
    }

    @Autowired
    private CheckClasssService checkClasssService;

    @RequestMapping("/CheckClassEdit")
    public String toedit(int id, Model model) {
        Result<CheckClass> getacheckclassrecord = checkClasssService.getacheckclassrecord(id);
        model.addAttribute("msg", getacheckclassrecord.getData());
        model.addAttribute("date", Tool.getDateToString(getacheckclassrecord.getData().getDate()));
        return "management/html/checkClass/edit";
    }


    @Autowired
    private CheckHealthsService checkHealthsService;

    @RequestMapping("/CheckHealthEdit")
    public String toCheckHealthEdit(int id, Model model) {
        Result<CheckHealth> oneById = checkHealthsService.getOneById(id);
        model.addAttribute("data", oneById.getData());
        model.addAttribute("date", Tool.getDateToString("yyyy-MM-dd hh:mm:ss", oneById.getData().getChecktime()));
        return "management/html/checkHealth/edit";
    }

    @Autowired
    private CheckMorningExercisesService checkMorningExercisesService;

    @RequestMapping("/CheckMorning")
    public String toMorning(int id, Model model) {
        Result<CheckMorningExercise> oneData = checkMorningExercisesService.getOneData(id);
        model.addAttribute("data", oneData.getData());
        model.addAttribute("date", Tool.getDateToString("yyyy-MM-dd hh:mm:ss", oneData.getData().getDate()));
        return "management/html/checkMorning/edit";
    }

    @Autowired
    private StudentsService studentsService;

    @RequestMapping("/studentEdit")
    public String toStudentEdit(int id, Model model) {
        Result<Student> oneStudent = studentsService.getOneStudent(id);
        model.addAttribute("data", oneStudent.getData());
        model.addAttribute("date", Tool.getDateToString(oneStudent.getData().getBirthday()));
        return "management/html/student/edit";
    }

    @Autowired
    private ClasssService classsService;

    @RequestMapping("/classEdit")
    public String toClassEdit(int id, Model model) {
        Result<Class> one = classsService.getOne(id);
        model.addAttribute("data", one.getData());
        model.addAttribute("date", Tool.getDateToString(one.getData().getCreattime()));
        model.addAttribute("semester", Semester.semester);
        List<Integer> ketset = new ArrayList<>(Semester.semester.keySet());
        model.addAttribute("semesterId", ketset);
        return "management/html/class/edit";

    }

    @Autowired
    private TeacherMapper teacherMapper;

    @RequestMapping("/teacherEdit")
    public String toTeacherEdit(int id, Model model) {
        Teacher oneTeacher = teacherMapper.getOneTeachers(id);

        model.addAttribute("data", oneTeacher);
        return "management/html/teacher/edit";
    }

    @RequestMapping("/addClass")
    public String toaddClass() {
        return "management/html/class/add";
    }

    @GetMapping("/login")
    public String toLogin(HttpServletRequest request) {
        if (webPath == null) {
            String scheme = request.getScheme();//http
            String serverName = request.getServerName();//localhost
            int serverPort = request.getServerPort();//8080
            String contextPath = request.getContextPath();//项目名
            webPath = scheme + serverName + serverPort + contextPath;
        }
        return "home/login";
    }

    @Autowired
    private SocietyForMapper societyForMapper;

    @RequestMapping("/enterScore")
    public String toEnterScore(int id, Model m) {
        SocietyFor societyFor = societyForMapper.selectById(id);
        m.addAttribute("data", societyFor);

        return "societyFor/html/Exam/enterScore";
    }


    /**
     * 检查班级接口
     *
     * @return
     */
    @RequestMapping("/examView")
    public String toExamView() {
        return "societyFor/html/Exam/ExamView";
    }

    @RequestMapping("/classRoom")
    public String toClassRoom() {
        return "management/html/classRoom/classRoom";
    }

    @RequestMapping("/studentAdd")
    public String toStudentAdd() {
        return "management/html/student/add";
    }

    @RequestMapping("/checkClass")
    public String toCheckClass() {
        return "management/html/checkClass/checkClass";
    }

    @RequestMapping("/checkHealth")
    public String toCheckHealth() {
        return "management/html/checkHealth/checkHealth";
    }

    @RequestMapping("/checkMorning")
    public String toCheckMorning() {
        return "management/html/checkMorning/checkMorning";
    }

    @RequestMapping("/toStudent")
    public String toStudent() {
        return "management/html/student/studentView";
    }

    @RequestMapping("/toClass")
    public String toClass() {
        return "management/html/class/classView";
    }

    @RequestMapping("/toTeacher")
    public String toTeacher() {
        return "management/html/teacher/teacherView";
    }

    @RequestMapping("/teacherAdd")
    public String toTeacherAdd() {
        return "management/html/teacher/add";
    }

    @RequestMapping("/toCouldFile")
    public String toCouldFile() {
        return "departmentPublic/html/CloudFile/cloudFile";
    }

    @RequestMapping("/toM9Statistics")
    public String tom9Statistics() {
        return "management/html/statistics/m9Statistics";
    }

    //region 实体类信息
    @GetMapping("/EScAuditone")
    public ScAuditone lx() {
        return new ScAuditone();
    }


    @GetMapping("/EScAudittwo")
    public ScAudittwo lx2() {
        return new ScAudittwo();
    }

    @GetMapping("/EScAuditthree")
    public ScAuditthree lx3() {
        return new ScAuditthree();
    }

    @GetMapping("/EScAuditfive")
    public ScAuditfive lx4() {
        return new ScAuditfive();
    }

    @GetMapping("/EScAuditfour")
    public ScAuditfour lx5() {
        return new ScAuditfour();
    }

    @GetMapping("/Activity")
    public Activity lx6() {
        return new Activity();
    }


    @GetMapping("/EAnnunciate")
    public Annunciate lx7() {
        return new Annunciate();
    }


    @GetMapping("/EAskOff")
    public AskOff lx8() {
        return new AskOff();
    }

    @GetMapping("/EAssignCompleteness")
    public AssignCompleteness lx9() {
        return new AssignCompleteness();
    }

    @GetMapping("/EAssignment")
    public Assignment lx11() {
        return new Assignment();
    }

    @GetMapping("/EIndexImage")
    public WxIndexImage lxWxIndexImage() {
        return new WxIndexImage();
    }

    @GetMapping("/EIndexImageType")
    public WxIndexImageType lxWxIndexImageType() {
        return new WxIndexImageType();
    }

    @GetMapping("/ESocietyFor")
    public SocietyFor lxSocietyFor() {
        return new SocietyFor();
    }

    @GetMapping("/ECheckClass")
    public CheckClass lx12() {
        return new CheckClass();
    }

    @GetMapping("/ECheckDorm")
    public CheckDorm lx13() {
        return new CheckDorm();
    }

    @GetMapping("/ECheckEvening")
    public CheckEvening lx14() {
        return new CheckEvening();
    }

    @GetMapping("/ECheckHealth")
    public CheckHealth lx15() {
        return new CheckHealth();
    }


    @GetMapping("/ECheckMorningExercise")
    public CheckMorningExercise lx16() {
        return new CheckMorningExercise();
    }

    @GetMapping("/EClass")
    public Class lx17() {
        return new Class();
    }

    @GetMapping("/EClassRoom")
    public ClassRoom lx18() {
        return new ClassRoom();
    }

    @GetMapping("/ECollectActivity")
    public CollectActivity lx19() {
        return new CollectActivity();
    }

    @GetMapping("/ECollectQuestion")
    public CollectQuestion lx20() {
        return new CollectQuestion();
    }

    @GetMapping("/ECollectTag")
    public CollectTag lx21() {
        return new CollectTag();
    }

    @GetMapping("/ECounsellor")
    public Counsellor lx22() {
        return new Counsellor();
    }


    @GetMapping("/ECourse")
    public Course lx23() {
        return new Course();
    }


    @GetMapping("/Eusermess")
    public Usermess show2() {
        return new Usermess();
    }

    @GetMapping("/Euser_attention")
    public UserAttention show3() {
        return new UserAttention();
    }

    @GetMapping("/Euser")
    public User show4() {
        return new User();
    }

    @GetMapping("/Eunread")
    public Unread show5() {
        return new Unread();
    }

    @GetMapping("/Eteacher")
    public Teacher show6() {
        return new Teacher();
    }

    @GetMapping("/Estudent")
    public Student show7() {
        return new Student();
    }

    @GetMapping("/Eskill_type")
    public SkillType show8() {
        return new SkillType();
    }

    @GetMapping("/Eskill_tag")
    public SkillTag show9() {
        return new SkillTag();
    }

    @GetMapping("/Eskill")
    public Skill show10() {
        return new Skill();
    }

    @GetMapping("/Esemester")
    public Semester show11() {
        return new Semester();
    }

    @GetMapping("/Erole_menu")
    public RoleMenu show12() {
        return new RoleMenu();
    }

    @GetMapping("/Erole")
    public Role show13() {
        return new Role();
    }

    @GetMapping("/Equestion_skill_tag")
    public QuestionSkillTag show14() {
        return new QuestionSkillTag();
    }

    @GetMapping("/Equestion")
    public Question show16() {
        return new Question();
    }

    @GetMapping("/Eon_duty")
    public OnDuty show17() {
        return new OnDuty();
    }

    @GetMapping("/Emenu")
    public Menu show18() {
        return new Menu();
    }

    @GetMapping("/Emake_up_lessons")
    public MakeUpLessons show19() {
        return new MakeUpLessons();
    }

    @GetMapping("/Efeedback")
    public Feedback show20() {
        return new Feedback();
    }

    @GetMapping("/Eevent")
    public Event show21() {
        return new Event();
    }

    @GetMapping("/Eevening_subject")
    public EveningSubject show22() {
        return new EveningSubject();
    }

    @GetMapping("/Edorm_student")
    public DormStudent show23() {
        return new DormStudent();
    }

    @GetMapping("/Edorm")
    public Dorm show24() {
        return new Dorm();
    }

    @GetMapping("/Ediscuss")
    public Discuss show25() {
        return new Discuss();
    }
    //endregion
}
